package remote{

	
	import entidades.RequisicaoCompra;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class RequisicaoRemote {
		
		public function verificaReqSolicit( result:Function, req:RequisicaoCompra ):void{
			var async:AsyncToken = _remote.verificaReqSolicit(req);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function recuperarReqAprov( result:Function ):void{
			var async:AsyncToken = _remote.recuperarReqAprov();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function reqAprov( result:Function ):void{
			var async:AsyncToken = _remote.reqAprov();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function exibirRequisicao( result:Function ):void{
			var async:AsyncToken = _remote.exibirRequisicao();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function buscarRequisicao(result:Function, numRequisicao:Number, urgencia:Number,
										 idStatus:Number, dtPlanejada:Date, dtCriacaoIni:Date, dtCriacaoFim:Date):void{
			var result:Function;
			var async:AsyncToken = _remote.buscarRequisicao(numRequisicao, urgencia,
				idStatus, dtPlanejada, dtCriacaoIni, dtCriacaoFim);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function buscarReq(result:Function, requisicao:Number):void{
			var result:Function;
			var async:AsyncToken = _remote.buscarItens(requisicao);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function gravarRequisicao(req:RequisicaoCompra ):void{
			var result:Function;
			var async:AsyncToken = _remote.addRequisicao(req);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		//--------------------setup----------------------------//
		private var _remote:RemoteObject;
		
		public function RequisicaoRemote(){
			_remote = new RemoteObject();
			_remote.showBusyCursor = true;
			_remote.destination = 'RequisicaoService';
		}
		
		private function defaultFaultHandler(e:FaultEvent):void{
			Alert.show( "Estamos com problemas no servidor! Tente novamente mais tarde!","Requisição" );
		}
		
		private static var _instance:RequisicaoRemote;
		public static function getInstance():RequisicaoRemote{
			if(_instance == null){
				_instance = new RequisicaoRemote();
			}
			return _instance;
		}
	}
}